package util;

import java.servlet.*;
import java.servlet.http.*;
import java.io.*;

public class IMGCreater extends HttpServlet{
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
		doPost(request, response);
	}
	
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{	
	 ServletOutputStream out = res.getOutputStream(); // binary output!
        Frame frame = null;
        Graphics g = null;
        try {
            // Create an unshown frame
            frame = new Frame();
            frame.addNotify();
            // Get a graphics region, using the Frame
            Image image = frame.createImage(400, 60);
            g = image.getGraphics();
            // Draw "Hello World!" to the off-screen graphics context
            g.setFont(new Font("CourierNew", Font.BOLD, 48));
            g.drawString("Hello World!", 10, 50);
            // Encode the off-screen image into a GIF and send it to the client
            res.setContentType("image/gif");
            GifEncoder encoder = new GifEncoder(image, out);
            encoder.encode();
        }
        finally {
            // Clean up resources
            if (g != null) g.dispose();
            if (frame != null) frame.removeNotify();
        }

	}
}